<template>
  <div style="background-color: rgb(239,235,235);padding: 20px 20%;min-height: 100vh">
    <el-card>
      <div style="display: flex;gap: 10px;height: 430px;">
        <div style="flex: 1">
          <image-preview :src="goods.img" style="width: 430px;height: 430px;"/>
        </div>
        <div style="flex: 1;display: flex;flex-direction: column;justify-content: space-between">
          <div>{{ goods.name }}</div>
          <div>销量{{ goods.count }}</div>
          <div>疯抢价：{{ goods.price }}</div>
          <div>
            <img src="@/assets/images/shop/right.png" alt="" style="border-radius: 10px;width: 300px;height: 140px;">
          </div>
          <div>商家：{{ goods.businessId }}</div>
          <div>分类：{{ goods.typeId }}</div>
          <div>
            <el-button @click="handleAdd" type="warning">加入购物车</el-button>
            <el-button @click="handleCollect" type="warning">收藏</el-button>
          </div>
        </div>
      </div>
      <el-tabs>
        <el-tab-pane label="宝贝详情">
          <div v-html="goods.description"/>
        </el-tab-pane>
        <el-tab-pane label="评价">
          <div style="min-height: 40vh"></div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>
<script>
import {getGoods} from "@/api/project/goods";
import {addCart} from "@/api/project/cart";
import {addCollect} from "@/api/project/collect";

export default {
  name: "goods-detail",
  created() {
    getGoods(this.$route.query.id).then(res => {
      this.goods = res.data
      this.form.goodsId = res.data.id
      this.form.businessId = res.data.businessId
    })
  },
  data() {
    return {
      goods: {},
      form: {},
    }
  },
  methods: {
    handleAdd() {
      addCart(this.form).then(res => {
        this.$message.success("加入购物车成功")
      })
    },
    handleCollect() {
      addCollect(this.form).then(res => {
        this.$message.success("收藏成功")
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
